<template>
  <div>
    <BasicTable @register="registerTable" :rowSelection="rowSelection" :dataSource="dataSource">
      <template #action="{ record }">
        <TableAction :actions="getActions(record)" />
      </template>
    </BasicTable>
    <TopicModal @register="registerModal" @success="reload" />
  </div>
</template>
<script lang="ts" name="connect-list" setup>
  import { reactive } from 'vue';
  import { BasicTable, TableAction } from '/@/components/Table';
  //   import { list, deleteTopic } from './topic.api';
  import { columns } from './topic.data';
  import { useListPage } from '/@/hooks/system/useListPage';
  import { useModal } from '/@/components/Modal';
  import TopicModal from './topicModal.vue';
  const [registerModal, { openModal }] = useModal();
  // 列表页面公共参数、方法
  const { tableContext } = useListPage({
    tableProps: {
      title: '连接管理',
      //   api: list,
      columns: columns,
      showIndexColumn: true,
      useSearchForm: false,
    },
  });

  const [registerTable, { reload }] = tableContext;

  const dataSource = reactive([
    {
      subscribeCount: 1,
      topic: '50',
    },
  ]);

  /**
   * 操作列定义
   * @param record
   */
  function getActions(record) {
    return [
      {
        label: '查看订阅',
        onClick: handleDetail.bind(null, record),
      },
    ];
  }

  function handleDetail(record) {
    openModal(true, {
      record,
      isUpdate: true,
    });
  }
</script>
